package com.sd.serv;

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DBServlet extends HttpServlet{
	
	public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
		try{
			
			
			String qry=req.getParameter("query");
			System.out.println(qry);
			
			
			
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","tiger");
			Statement st=conn.createStatement();
			ResultSet rs=st.executeQuery(qry);
			
			PrintWriter out=res.getWriter();
			out.println("<html>");
			out.println("<body>");
			out.println("<table border=0 width=100%>");
			out.println("<tr>");
			out.println("<th>ID</th>");
			out.println("<th>Name</th>");
			out.println("<th>SAl</th>");
			out.println("</tr>");
			
			while(rs.next()){
				out.println("<tr>");
				out.println("<td>"+rs.getInt(1)+"</td>");
				out.println("<td>"+rs.getString(2)+"</td>");
				out.println("<td>"+rs.getInt(3)+"</td>");
				out.println("<tr>");
			}
			conn.close();
			out.println("</table></body></html>");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	//public void doPost(HttpServletRequest req,HttpServletResponse res){
	//	doPost(req,res);
	//}
}
